package com.liyuci.core.entity;

import com.fasterxml.jackson.annotation.JsonFormat;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;

import lombok.Data;

import org.hibernate.annotations.GenericGenerator;

/**
 * 基类实体类.
 * @author liyuci
 * @date 2017-10-24 11:32:42
 */
@Data
@MappedSuperclass
@SuppressWarnings("serial")
public abstract class BaseModel implements Serializable
{

	/**
	 * id生成策略的名称
	 */
	private static final String GENERATOR_NAME = "idGenerator";
	/**
	 * id生成策略的方式
	 */
	private static final String GENERATOR_STRATEGY = "uuid";

	/**
	 * 定义浮点数的位数
	 */
	public static final int COLUMN_PRECISION = 19;
	/**
	 * 定义浮点数的小数点后保留位数
	 */
	public static final int COLUMN_SCALE = 4;

	public static final String YES = "1";
	public static final String NO = "0";

	@Id
	@GenericGenerator(name = GENERATOR_NAME, strategy = GENERATOR_STRATEGY)
	@GeneratedValue(generator = GENERATOR_NAME)
	public String id;
	public String name;
	public String delFlag = YES;
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", locale = "zh", timezone = "GMT+8")
	public Date createDate;
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", locale = "zh", timezone = "GMT+8")
	public Date updateDate;

	@PrePersist
	public void prePersist()
	{
		this.createDate = new Date();
		this.updateDate = new Date();
	}

	@PreUpdate
	public void preUpdate()
	{
		this.updateDate = new Date();
	}

}
